//
//  SLInformationOptionComponent.m
//  SulitLoanDemo
//
//  Created by 虞嘉伟 on 2025/2/22.
//

#import "SLInformationOptionComponent.h"
#import <YYKit.h>
#import <Masonry.h>

@implementation SLInformationOptionComponent

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.bgView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.textField];
        [self addSubview:self.more];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self).inset(0);
            make.top.bottom.equalTo(self).inset(0);
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.bgView).inset(14);
            make.top.equalTo(self.bgView).inset(12.5);
            make.height.mas_equalTo(18);
        }];
        [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(0);
            make.bottom.equalTo(self.bgView).inset(12.5);
        }];
        [self.more mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgView).inset(15);
            make.centerY.equalTo(self.textField);
            make.width.height.mas_equalTo(22);
            //make.width.mas_equalTo(self.more.mas_height);
        }];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    if (self.more.isHidden) {
        [self.textField mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgView).inset(12.5);
        }];
    } else {
        [self.textField mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.more.mas_left).inset(12.5);
        }];
    }
}
- (void)setMoreCallback:(dispatch_block_t)moreCallback {
    _moreCallback = moreCallback;
    if (moreCallback) {
        self.more.hidden = NO;
        self.textField.enabled = NO;
    } else {
        self.more.hidden = YES;
        self.textField.enabled = YES;
    }
    [self setNeedsLayout];
}
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.layer.cornerRadius = 15;
        _bgView.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _bgView.layer.borderWidth = 1;
    }
    return _bgView;
}
- (UIView *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = UIColorHex(#1B1B1B);
        _titleLabel.font = aspectBoldFont(14);
    }
    return _titleLabel;
}
- (UITextField *)textField {
    if (!_textField) {
        _textField = [UITextField new];
        _textField.textColor = UIColorHex(#1B1B1B);
        _textField.font = aspectDefaultFont(14);
    }
    return _textField;
}
- (UIImageView *)more {
    if (!_more) {
        _more = [UIImageView new];
        _more.layer.cornerRadius = 2;
        _more.contentMode = UIViewContentModeScaleAspectFit;
        _more.image = [UIImage imageNamed:@"btn_more_black"];
    }
    return _more;
}
@end
